<html>
<head><meta charset="utf-8"><title>Unpoisoning mutex · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html">Unpoisoning mutex</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="194603705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194603705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194603705">(Apr 19 2020 at 15:43)</a>:</h4>
<p>Is this possible to force unpoisoning a poisoned mutex?</p>



<a name="194603770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194603770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194603770">(Apr 19 2020 at 15:45)</a>:</h4>
<p>you can call <code>.into_inner()</code> on the <code>PoisonError</code></p>



<a name="194603855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194603855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194603855">(Apr 19 2020 at 15:46)</a>:</h4>
<p>yep, i tried that, but then i get back a mutexguard right? if i want to unlock that guard, i tried to <code>drop(guard);</code> but next <code>mutex.lock</code> still returned a poisoned guard</p>



<a name="194603976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194603976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194603976">(Apr 19 2020 at 15:49)</a>:</h4>
<p>well i could use that guard to access again the underlying object, but since its poisoned its a very fragile thing to do i guess</p>



<a name="194604245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194604245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194604245">(Apr 19 2020 at 15:55)</a>:</h4>
<p>no, poisoned mutexes aren't curable :)</p>



<a name="194604366"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194604366" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194604366">(Apr 19 2020 at 15:56)</a>:</h4>
<p>Thats what i thought</p>



<a name="194606170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194606170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194606170">(Apr 19 2020 at 16:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/122651-general/topic/Unpoisoning.20mutex/near/194604245" title="#narrow/stream/122651-general/topic/Unpoisoning.20mutex/near/194604245">said</a>:</p>
<blockquote>
<p>no, poisoned mutexes aren't curable :)</p>
</blockquote>
<p>that's susprisng, seems to me like the next regular unlock should cure them</p>



<a name="194606228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194606228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194606228">(Apr 19 2020 at 16:30)</a>:</h4>
<p>That would be interesting</p>



<a name="194606329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194606329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194606329">(Apr 19 2020 at 16:32)</a>:</h4>
<p>But it's not what is implemented today at least</p>



<a name="194606360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194606360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194606360">(Apr 19 2020 at 16:33)</a>:</h4>
<p>we never store false into the poison flag after setting it</p>



<a name="194606420"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194606420" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194606420">(Apr 19 2020 at 16:34)</a>:</h4>
<p>hm. I guess there is no guarantee that the unlock indeed restored the invariant</p>



<a name="194606424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194606424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194606424">(Apr 19 2020 at 16:34)</a>:</h4>
<p>so maybe it should be explicit</p>



<a name="194606433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194606433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194606433">(Apr 19 2020 at 16:34)</a>:</h4>
<p>yeah -- we could provide a clear() on the mutexguard</p>



<a name="194606454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194606454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194606454">(Apr 19 2020 at 16:35)</a>:</h4>
<p>I'm not sure how useful that would be given that poisoning is generally questionably useful anyway :)</p>



<a name="194606511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194606511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194606511">(Apr 19 2020 at 16:36)</a>:</h4>
<p>at least in the code I've written I either don't care (and so always do the <code>unwrap_or_else(|e| e.into_guard())</code> dance) or just unwrap</p>



<a name="194606523"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194606523" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194606523">(Apr 19 2020 at 16:36)</a>:</h4>
<p>It is very useful. Otherwise the main thread would likely continue after an unexpected panic of a background thread.</p>



<a name="194606555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194606555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194606555">(Apr 19 2020 at 16:37)</a>:</h4>
<p>Hm, well, I mean, I guess it <em>can</em> be useful</p>



<a name="194606575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194606575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194606575">(Apr 19 2020 at 16:37)</a>:</h4>
<p>but I'm just saying that it's not obvious that Mutex in std should enforce it</p>



<a name="194606587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194606587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194606587">(Apr 19 2020 at 16:38)</a>:</h4>
<p>anyway I'd be unopposed to providing a clear_poison function or so</p>



<a name="194606649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194606649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194606649">(Apr 19 2020 at 16:38)</a>:</h4>
<p>If std::sync::Mutex doesn't implement poison, it is very likely that most people won't bother to implement something to stop the program when a background thread panics.</p>



<a name="194606657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194606657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194606657">(Apr 19 2020 at 16:38)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/122651-general/topic/Unpoisoning.20mutex/near/194606587" title="#narrow/stream/122651-general/topic/Unpoisoning.20mutex/near/194606587">said</a>:</p>
<blockquote>
<p>anyway I'd be unopposed to providing a clear_poison function or so</p>
</blockquote>
<p>me neither</p>



<a name="194614808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194614808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194614808">(Apr 19 2020 at 19:47)</a>:</h4>
<p>Its not necessarily true that just ignoring poison makes the data actually valid.</p>



<a name="194614827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/194614827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#194614827">(Apr 19 2020 at 19:47)</a>:</h4>
<p>e.g. things like a print routine doesn’t actually care if a structure is half updated, but an algorithm might</p>



<a name="227663145"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227663145" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227663145">(Feb 24 2021 at 20:08)</a>:</h4>
<p>Sorry for the thread resurrection, but I was just asked if this existed during a training, so it's not just you that wanted it!</p>



<a name="227716098"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227716098" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227716098">(Feb 25 2021 at 04:30)</a>:</h4>
<p>It is very non-obvious to me how to review code to validate the correctness of a call to <code>Mutex::clear_poison</code>. You are basically in C++'s exception safety regime here: just about everything could panic, and so it's really hard to say what state the mutex is in. Seems easier to just mem::replace it with a new one</p>



<a name="227720136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227720136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227720136">(Feb 25 2021 at 05:26)</a>:</h4>
<p>That's a sane course of action, and if we're not going to add <code>clear_poison</code> then we should make an example for that in the docs.</p>



<a name="227721486"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227721486" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227721486">(Feb 25 2021 at 05:48)</a>:</h4>
<p>Of course using mem::replace means that you have mutable access to the mutex, meaning that you have to stop all threads that have access to it, so the technique is not often applicable. If it's a global then you need to have a mutex to protect the mutex...</p>



<a name="227800828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227800828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227800828">(Feb 25 2021 at 17:03)</a>:</h4>
<p>oh right, that too</p>



<a name="227934999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227934999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227934999">(Feb 26 2021 at 14:27)</a>:</h4>
<blockquote>
<p>what state the mutex is in</p>
</blockquote>
<p>The <em>mutex</em> itself should always be in a defined state, but the data within in might not be, correct?</p>



<a name="227935359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227935359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227935359">(Feb 26 2021 at 14:30)</a>:</h4>
<blockquote>
<p>so it's really hard to say what state the mutex is in</p>
</blockquote>
<p>Given that view, then it should be completely disallowed to access the data after the mutex has been poisoned. There are cases where the state of the data can be re-established to a known-good condition, which is why an unpoison makes sense to me.</p>



<a name="227940135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227940135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227940135">(Feb 26 2021 at 15:04)</a>:</h4>
<p>Not quite, because you don't even know if there <em>is</em> a bad state in the first place.</p>



<a name="227941329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227941329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227941329">(Feb 26 2021 at 15:13)</a>:</h4>
<p>Not quite... what? Can you clarify which part you are responding to?</p>



<a name="227946603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227946603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227946603">(Feb 26 2021 at 15:50)</a>:</h4>
<p>Mutex poisoning is useful for when the inner state may have violated a logic invariant. Even a poisoned mutex may not have inner state that violates a safety invariant. A logic invariant may still be restorable and as such the mutex should be unpoisonable. It can also sometimes be useful to access the data anyway despite the violated logic invariant. You just have to be more careful.</p>



<a name="227947364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227947364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227947364">(Feb 26 2021 at 15:56)</a>:</h4>
<p>Right, I completely agree :-)</p>



<a name="227947561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227947561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227947561">(Feb 26 2021 at 15:57)</a>:</h4>
<p>The example we were using during training was <code>Mutex&lt;(u8, u8)&gt;</code> where the first value must always be one less than the second value. It's easy to demonstrate how that can get into a logically-inconsistent form thanks to a panic.</p>



<a name="227947772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227947772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227947772">(Feb 26 2021 at 15:59)</a>:</h4>
<p>Rust will prevent the data inside from being memory-unsafe, and it's conceivable for the application to be able to roll back or otherwise recover the state to a consistent point, at which point any future poison notification would be superfluous.</p>



<a name="227969555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227969555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227969555">(Feb 26 2021 at 18:22)</a>:</h4>
<p>Right, as you two already covered, i was responding to the "you can never recover from poison" argument. Which is clearly wrong. You don't even know if the panic happened on protected data or if it happened with other code while the lock just happened to be held.</p>



<a name="227978907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227978907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227978907">(Feb 26 2021 at 19:26)</a>:</h4>
<p>In complicated back-and-forth, Zulip allows you to quote / reply to a specific post to help track the threads of conversation:</p>
<p><a href="/user_uploads/4715/iSRNXdGkAqQihGBmtWRqbSBt/image.png">image.png</a> </p>
<div class="message_inline_image"><a href="/user_uploads/4715/iSRNXdGkAqQihGBmtWRqbSBt/image.png" title="image.png"><img src="/user_uploads/4715/iSRNXdGkAqQihGBmtWRqbSBt/image.png"></a></div><p>May be helpful to avoid similar confusion in the future.</p>



<a name="227985710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227985710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227985710">(Feb 26 2021 at 20:11)</a>:</h4>
<p>you actually can't do that on mobile</p>



<a name="227992772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/227992772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#227992772">(Feb 26 2021 at 20:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/122651-general/topic/Unpoisoning.20mutex/near/227985710">said</a>:</p>
<blockquote>
<p>you actually can't do that on mobile</p>
</blockquote>
<p>You can, in the browser</p>



<a name="228038524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/228038524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#228038524">(Feb 27 2021 at 06:42)</a>:</h4>
<p>I mean, the site works well enough in a mobile browser that I skipped the app</p>



<a name="228040228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/228040228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#228040228">(Feb 27 2021 at 07:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/122651-general/topic/Unpoisoning.20mutex/near/227969555">said</a>:</p>
<blockquote>
<p>Right, as you two already covered, i was responding to the "you can never recover from poison" argument. Which is clearly wrong. You don't even know if the panic happened on protected data or if it happened with other code while the lock just happened to be held.</p>
</blockquote>
<p>I don't think that "you can never recover from poison" is correct, but if you could just unset the poison flag then you could get access to the data of type <code>T</code> again, which might violate library invariants on the data, which may or may not be promoted to safety invariants through the use of otherwise reasonable unsafe code behind a module abstraction. I think it should be okay to leverage the interior mutability to reset the state, i.e. reset the flag and replace the inner <code>T</code> with a provided value, but if you want to access the corrupted <code>T</code> value that should probably be an unsafe function</p>



<a name="228060395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/228060395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#228060395">(Feb 27 2021 at 14:05)</a>:</h4>
<p>but you can <em>already</em> do that with the error's into_inner method, as a safe function.</p>



<a name="228060472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/228060472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#228060472">(Feb 27 2021 at 14:06)</a>:</h4>
<p><a href="https://doc.rust-lang.org/std/sync/struct.PoisonError.html#method.into_inner">https://doc.rust-lang.org/std/sync/struct.PoisonError.html#method.into_inner</a></p>



<a name="228060518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/228060518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#228060518">(Feb 27 2021 at 14:07)</a>:</h4>
<p>So any code that relies on a mutex invariant for safety is already wrong.</p>



<a name="228118763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/228118763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#228118763">(Feb 28 2021 at 09:34)</a>:</h4>
<p>Those functions should have warnings on them similar to <code>AssertUnwindSafe</code>, which is also not actually unsafe</p>



<a name="228118855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/228118855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#228118855">(Feb 28 2021 at 09:36)</a>:</h4>
<p>In fact this might even be the exact same invariant as unwind safety</p>



<a name="228161939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unpoisoning%20mutex/near/228161939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unpoisoning.20mutex.html#228161939">(Feb 28 2021 at 22:33)</a>:</h4>
<p><code>AssertUnwindSafe</code> is a poorly named thing.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>